//    Copyright (C) Kherty.  All rights reserved.
using System;
using System.Diagnostics;
using System.Diagnostics.Contracts;

namespace OpenLS.Spreadsheet.Extensibility
{
    public class ConversionData
    {
        private readonly IWorkbook _workbook;
        private readonly IWorksheet _worksheet;
        public override string ToString()
        {
            return string.Format("Value ={0}, Result = {1}, Error = {2}, TargetType = {3}, Successful = {4}", Value, Result, Error, TargetType, Successful);
        }

        public ConversionData(IWorkbook workbook, IWorksheet worksheet, object source, Type targetType)
        {
            Contract.Requires(workbook != null);
            Contract.Assert(workbook != null);
            _workbook = workbook;
            _worksheet = worksheet;
            this.Value = source;
            this.TargetType = targetType;
           // _dateTimeOrigin = dateTimeOrigin;
        }

        public IWorkbook Workbook
        {
            get { return _workbook; }
        }

        private object _value;
        public object Value
        {
            get { return _value; }
            private set
            {
                _value = value;
            }
        }

        internal void Dereference()

        {
            this.Value = ((ICell) Value).Value;
            this.Dereferenced = true;
        }

        internal bool Dereferenced { get; private set; }

        public Type TargetType { get; private set; }
        private bool _ignore;


        public IWorksheet Worksheet
        {
            get { return _worksheet; }
        }

        public bool Ignore
        {
            get { return _ignore; }
            set
            {
                if (_ignore == value)
                    return;
                Changed = true; _ignore = value;
            }
        }

        private Error _error;

        public Error Error
        {
            get { return _error; }
            set
            {
                if (_error == value)
                    return;
                Changed = true; _error = value;
                Successful = false;
            }
        }

        private object _result;

        public object Result
        {
            get { return _result; }
            set { Changed = true; _result = value;
                Successful = true; }
        }

        public bool Successful { get; private set; }

        private bool Changed { get; set; }
    }
}